<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.liit.util.PropertiesUtils"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="cn.liit.weixin.core.config.Config"%>
<!DOCTYPE HTML>
<html>
<title>活动报名列表</title>
<%@include file="/common/wxCommon.jspf"%>
<style>
.weui_cell:before {
	left: 0px;
}
body {
	background-color: #F1F1F1;
}
.weui-row {
	padding: 5px 15px;
}
.weui-row h4 {
	color: black;
	font-size: 14px
}
.weui-row p label{
	color: #8A8A8A;
	font-size: 13px
}
.weui-row p {
	color: #5D5D5D;
	font-size: 13px
}
.weui_panel {
	margin-top: 5px
}
img {
	width: 100%;
	max-height: 100px;
}
.weui_panel_hd {
	color: black;
	text-align: center;
}
</style>
<body ontouchstart>
	<div class="weui_msg hide">
		<div class="weui_icon_area">
			<i class="weui_icon_info weui_icon_msg"></i>
		</div>
		<div class="weui_text_area">
			<p class="weui_msg_desc">暂无可报名活动</p>
		</div>
	</div>
	<div class="bd">
		<div class="weui_panel weui_panel_access hide" id="recommend">
			<div class="weui_panel_hd">推荐活动</div>
		</div>
		<div class="weui_panel weui_panel_access hide" id="new">
			<div class="weui_panel_hd">最新活动</div>
		</div>
		
	</div>
	
	<div class="weui_panel weui_panel_access hide" id="template">
		<div class="weui_panel_bd">
			<a href="javascript:void(0);">
				<div class="weui-row">
					<h4 id="title"></h4>
				</div>
				<div class="weui-row">
					<div class="weui-col-33">
						<img src="${ctx}/images/weixin/nothing.png" alt="">
					</div>
					<div class="weui-col-66">
						<p></p>
						<p></p>
						<p></p>
						<p></p>
					</div>
				</div>
			</a>
		</div>
	</div>
	<script type="text/javascript">
		var partyType = [];
		<c:forEach items="${partyType}" var="record">
			partyType.push({label : "${record.label}", value : "${record.value}"});
		</c:forEach>
		var noData = false;
		var pageNow = 1;
		var loading = false;
		$(document.body).infinite().on("infinite", function() {
		    loadData();
		});
		
		//加载普通活动
		function loadData() {
			if (loading) return;
		    loading = true;
			$.getJSON(rootPath + '/weixin/user/party/listPartyByPage.shtml', {'pageNow' : pageNow, 'pageSize' : 10, type :　0}, function(result){
	    		$.each(result.records, function(i, e){
	    			 var template = $($("#template").prop("outerHTML"));
		        	 template.removeAttr("id");
		        	 template.removeClass("hide");
		        	 template.find("a").attr("href",getSignPartyUrl(e.id));
		        	 template.find("#title").html(e.subject);
		        	 if (e.partyImage != null) {
		        		 template.find("img").attr("src", "${ctx}/upload/party/" + e.partyImage);
		        	 }
		        	 var desc = template.find("p");
		        	 desc.eq(0).html("<label>活动类型:&nbsp;</label>" + getLabel(e.type));
		        	 desc.eq(1).html("<label>开始时间:&nbsp;</label>" + (new Date(e.startTime).format("M月dd日 hh:mm")));
		        	 desc.eq(2).html("<label>地&emsp;&emsp;点:&nbsp;</label>" + e.area + "," + e.street);
		        	 desc.eq(3).html("<label>联&nbsp;&thinsp;&thinsp;系&thinsp;&thinsp;人:&nbsp;</label>" + e.contact + "(" + e.phone + ")");
		        	 
		        	 $("#new").after(template);
		        });
		    	pageNow += 1;
		    	loading = false;
		    	if (pageNow > result.pageCount) {
					$(document.body).destroyInfinite();
				}
		    	
		    	if (noData && result.records.length == 0) {
	    			$("div.weui_msg").removeClass("hide");
	    		} else if (result.records.length > 0) {
	    			$("#new.hide").removeClass("hide");
	    		}
		    });
		}
		$(function(){
			
			//加载推荐活动
			$.getJSON(rootPath + '/weixin/user/party/listPartyByPage.shtml', {'pageNow' : 1, 'pageSize' : 1000, type :　1}, function(result){
	    		$.each(result.records, function(i, e){

	    			 var template = $($("#template").prop("outerHTML"));
		        	 template.removeAttr("id");
		        	 template.removeClass("hide");
		        	 template.find("a").attr("href",getSignPartyUrl(e.id));
		        	 template.find("#title").html("<i class='party_rec'></i>" + e.subject);
		        	 if (e.partyImage != null) {
		        		 template.find("img").attr("src", "${ctx}/upload/party/" + e.partyImage);
		        	 }
		        	 var desc = template.find("p");
		        	 desc.eq(0).html("<label>活动类型:&nbsp;</label>" + getLabel(e.type));
		        	 desc.eq(1).html("<label>开始时间:&nbsp;</label>" + (new Date(e.startTime).format("M月dd日 hh:mm")));
		        	 desc.eq(2).html("<label>地&emsp;&emsp;点:&nbsp;</label>" + e.area + "," + e.street);
		        	 desc.eq(3).html("<label>联&nbsp;&thinsp;&thinsp;系&thinsp;&thinsp;人:&nbsp;</label>" + e.contact + "(" + e.phone + ")");
		        	 
		        	 $("#recommend").after(template);
		        });
	    		
	    		if (result.records.length == 0) {
	    			noData = true;
	    		} else {
	    			$("#recommend.hide").removeClass("hide");
	    		}

	    		loadData();
		    });
		});
		
		function getLabel(val) {
			var label = "";
			$.each(partyType, function(i, e) {
				if (val == e.value) {
					label = e.label;
					return false;
				}
			});
			return label;
		}
		
		//活动报名
		function getSignPartyUrl(partyId) {
			return "<%=String.format(PropertiesUtils.findPropertiesKey("auth.url"), 
								Config.appid, URLEncoder.encode(Config.notifyurl + request.getContextPath()
								+ "/weixin/user/party/signParty.shtml?partyId=" , "UTF-8") + "{0}")%>".replace("{0}",partyId);
		}
		
		//微信分享处理
		wx.ready(function() {
			var signPartyUrl = "<%=Config.notifyurl  + request.getContextPath()%>/weixin/user/listparty.shtml";
			var partyImage = "<%=Config.notifyurl  + request.getContextPath()%>/images/weixin/share.png";
			wx.onMenuShareTimeline({
			    title: '活动分享', // 分享标题
			    link: signPartyUrl, // 分享链接
			    imgUrl: partyImage // 分享图标
			});
			
			wx.onMenuShareAppMessage({
			    title: '活动分享', // 分享标题
			    desc: '推荐活动,最新活动分享', // 分享描述
			    link: signPartyUrl, // 分享链接
			    imgUrl: partyImage // 分享图标
			});
			
			wx.hideMenuItems({
			      menuList: [ 'menuItem:share:qq', 'menuItem:share:weiboApp',  'menuItem:share:QZone' ]
			});
		});
	</script>
</body>
</html>